﻿using System;
using System.Linq;
using System.Windows.Forms;
using MovieBrowser.Model;

namespace MovieBrowser.Presentation.Forms.Db
{
    public partial class MovieUpdateForm : Form
    {
        private readonly MovieDbEntities _entities;
        private readonly Movie _rowMovie;

        public MovieUpdateForm(MovieDbEntities entities, Movie rowMovie)
        {
            InitializeComponent();
            _entities = entities;
            _rowMovie = rowMovie;
        }

        private void MovieFormLoad(object sender, EventArgs e)
        {
            if (_rowMovie != null && _rowMovie.ImdbId != null)
                movieBindingSource.DataSource = _entities.Movies.Where(o => o.ImdbId == _rowMovie.ImdbId);
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            _entities.SaveChanges();
            Hide();
        }
    }
}
